from fastapi import APIRouter,Response
from fastapi.responses import JSONResponse

router = APIRouter()

@router.get("/header")
async def create_header(response: Response):
    response.headers["X-Token"] = "abc123"
    return {"msg": "这是响应的主体内容"}


@router.get("/header2")
async def get_headers():
    content = {"message":"这是主体中内容"}
    headers = {"X-Token":"abc123"}
    return JSONResponse(content=content,headers=headers)